<!-- home -->
<template>
  <page-view :full="true">
    <top-bar title="基础验证"
             :white="false">
    </top-bar>
    <page-content>
      <div class="cf-con">
        <div class="cf-item">
          <span class="cf-name">姓名</span>
          <input type="text"
              v-model="fullname"    
              placeholder="请输入您的真实姓名"
              class="cf-input">
        </div>
        <div class="cf-item">
          <span class="cf-name">身份证号码</span>
          <input type="text"
              v-model="idcard"    
              placeholder="请输入您的身份证号码"
              class="cf-input">
        </div>
      </div>
      <div class="btn-box">
        <van-button round
                    type="info"
                    :disabled="!fullname && !idcard"
                    @click="save"
                    class="cf-btn">提交</van-button>
      </div>
    </page-content>
  </page-view>
</template>

<script>
import TopBar from '@/components/TopBar';
import PageView from '@/components/PageView';
import PageContent from '@/components/PageContent';
import service from '@/utils/request';
import { Dialog } from 'vant';

export default {
  data () {
    return {
      idcard: '',
      fullname: '',
      user: {}
    }
  },
  components: {
    TopBar,
    PageView,
    PageContent
  },
  mounted () { },
  created(){
    this.user = this.$store.state.user;
  },
  methods: {
    save(){
      if(!this.fullname){
        Dialog({ 
          title: '提示',
          message: '请输入真实姓名！' 
        })
        return;
      }
      if(!this.idcard || (this.idcard.length != 15 && this.idcard.length != 18)){
        Dialog({ 
          title: '提示',
          message: '请输入正确的身份证号码！' 
        })
        return;
      }
      return service.post('/apiModifyMy.do', {
        nickname: this.fullname,
        idcard: this.idcard
      }).then(res=>{
        this.user.fullname = this.fullname;
        this.user.idcard = this.idcard;
        this.$store.dispatch('setUser', this.user);
        this.$router.go(-1);
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.btn-box {
  text-align: center;
}
.cf-con {
  height: 110px;
  box-sizing: border-box;
  background: #fff;
  padding: 0 20px;
  margin-top: 70px;
  .cf-item {
    height: 55px;
    line-height: 55px;
    overflow: hidden;
    .cf-name {
      display: inline-block;
      width: 100px;
      font-size: 16px;
      color: #3d3e54;
    }
    .cf-input {
      border: 0;
      font-size: 16px;
      font-weight: 400;
      color: #7a7886;
    }
  }
}
.cf-btn {
  width: 335px;
  height: 57px;
  line-height: 57px;
  background: #585df9;
  border-radius: 29px;
  text-align: center;
  font-size: 17px;
  font-weight: 500;
  color: #ffffff;
  position: fixed;
  margin: 0 auto;
  left: 0;
  right: 0;
  bottom: 95px;
}
</style>
